package com.bms.client.controller;

import com.bms.client.pojo.Test;
import com.bms.client.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zcx
 * @version 1.0
 * @description Test.java
 * @date 2021/3/21 20:30
 */
@RestController
@RequestMapping("Test")
@Api(value = "Test",tags = "Test")
public class MyTest {
    @Resource
    private RedisUtils redisUtils;
    @RequestMapping(value = "test1", method = RequestMethod.GET)
    @ApiOperation(value = "test1",notes = "test1",httpMethod = "GET")
    public void test1(){
        Test test=new Test();
        test.setId("1");
        test.setName("zcx");
        test.setSex("男");
        Map<String,String> map=new HashMap<>();
        map.put("username",test.getName());
        map.put("sex","男");
        System.out.println( redisUtils.redisInsert("zcx",map,"1",test));
        test=new Test();
        test.setId("2");
        test.setName("zcx2");
        test.setSex("男1");
        Map<String,String> map1=new HashMap<>();
        map1.put("username","zcx2");
        map1.put("sex","男1");
        System.out.println( redisUtils.redisInsert("zcx",map1,"2",test));
//        Test test1=(Test)redisUtils.get();
//        System.out.println(test1);
    }
    @RequestMapping(value = "test2", method = RequestMethod.GET)
    @ApiOperation(value = "test2",notes = "test1",httpMethod = "GET")
    public void test2(String tableName,String id){
        System.out.println( redisUtils.redisDelete(tableName,id));
    }
    @RequestMapping(value = "test3", method = RequestMethod.GET)
    @ApiOperation(value = "test3",notes = "test3",httpMethod = "GET")
    public Map<String, Object> test3(int page,String username,@RequestParam(name = "sex",required = false) String sex){
        Map<String,String> map=new HashMap<>();
        map.put("username","*"+username+"*");
        map.put("sex",sex);
        System.out.println("sex"+sex);
        return redisUtils.redisPage(page,"zcx",map);
    }
}
